
package tankapp.views;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import tankapp.controllers.Controller;
import tankapp.models.Model;

public class View extends JPanel{
    private Controller controller = null;
    
    public Controller getController() {
        return controller;
    }
    
    public void setController(Controller controller) {
        this.controller = controller;
    }
    
    double x = 0;
    Image map = null;
    
    @Override
    public void paint(Graphics g){
        try {
            if( map == null ){
                map = ImageIO.read(new File("./media/map.jpg"));
            }
        } catch (IOException ex) {
            Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        Model model = controller.getModel();
        g.setColor(Color.white);
        g.fillRect(0, 0, 800, 600);
        g.drawImage(map, 0, 0, getWidth(), getHeight(), (int)model.getX(), (int)model.getY(), getWidth()+(int)model.getX(), getHeight()+(int)model.getY(), this);
    }
    
}
